package SiTuQingYou.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import SiTuQingYou.util.DBHelper;
import SiTuQingYou.vo.SceneClass;

public class SceneClassDao 
{
	private  SceneClassDao() {}
	private static  SceneClassDao scd= new  SceneClassDao();
	public static  SceneClassDao getscd()
	{
		return scd;
	}
	public ArrayList<SceneClass> getsceneclass()
	 {
	    Connection conn=null;
	    PreparedStatement ps=null;
	    ResultSet rs=null;
	    try {
	     ArrayList<SceneClass> scs=new ArrayList<SceneClass>();
	    conn=DBHelper.getDB().getConn();
	    String sql="select * from sceneclass";
	    ps=conn.prepareStatement(sql);
	    rs=ps.executeQuery();
	    while(rs.next())
	    {
	    SceneClass scd=new SceneClass();
	    scd.setClassphoto(rs.getString("classphoto"));
	    scd.setClassname(rs.getString("classname"));
	    scd.setId(rs.getInt("id"));
	    scs.add(scd);
	    
	    }
	    return scs;
	    } catch (Exception e) {
	    	  e.printStackTrace();
	    	 }
	    	    finally
	    	    {
	    	     DBHelper.getDB().close(rs, ps, conn);
	    	    }
	    	    return null;
	    	   
	    	    
	    	 }
	public  ArrayList<SceneClass>  sceneclass() {
		
		DBHelper dbhelper = DBHelper.getDB();
		  Connection conn = null;
			PreparedStatement ps = null;
			ResultSet rs = null; 
		
			 
		 try {
			 conn = dbhelper.getConn();
			 String sql = "select * from sceneclass";
			 ps = conn.prepareStatement(sql);
			 rs = ps.executeQuery();
			 ArrayList<SceneClass> allclass = new ArrayList<SceneClass>();
					 while(rs.next()) {
				 SceneClass scenec = new SceneClass();
				 scenec.setId(rs.getInt("id"));
				 scenec.setClassname(rs.getString("classname"));
				 allclass.add(scenec);
			 }
			
			 return allclass;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
			finally {
				dbhelper.close(rs, ps, conn);
			}
			return null;
	}
}
